<--- %%NOBANNER%% --> readfile.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| Read in a file into a dataset.                                     |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|-----------<-- Start of Files or Arguements Needed-->---------------|
| Arguments:                                                         |
|    file - the filename you want to read in;                        |
|    outdata - the output data set to save the contents of the file. |
|-----------------<-- End of Arguements Needed-->--------------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %readfile(d:\web\sasmacros\temp1.log, outdata=filecnt);   |
\-------------------<-- End of Files Created-->---------------------*/
%macro readfile(file=, stopsign='----*/', outdata=_tmp) ;
/*--------------------------------------------\
| Author:  Duo Zhou;                          |
| Created: 1-1-2002 9:50am;                   |
| Purpose: Read in the contents of a file     |
\--------------------------------------------*/
%local _tmplast_; %let _tmplast_=&syslast;
%if (%sysfunc(fileexist(&file))) %then %do;
   filename indata "&file";
   /* Your data step code for this file.  */
   DATA _tmp1;
      infile indata length=linelen;
      length line $ 2000;
      do until(index(line, &stopsign));
         input @1 line $ varying200. linelen;
         output;
      end;
   PROC print data=_tmp1; title "Contents of &file"; run;
   %if (%quote(&outdata) ne) %then %do;
      data &outdata; set _tmp1; run;
   %end;
   %else %let syslast=&_tmplast_;
   %if (%quote(%upcase(&outdata)) ne %quote(_TMP1)) %then %do;
   proc sql; drop table _tmp1; quit;
   %end;
%end;
%else %put --> NOTE: The file "&file" does not exist.;
%mend readfile;